function showTime(){
	var d = new Date();
	var year = d.getFullYear();
	var month = d.getMonth()+1;
	var day = d.getDate();
	var hour = d.getHours();
	var min = d.getMinutes();
	if(min<10) min = "0"+min;
	var s = d.getSeconds();
	if(s<10) s= "0"+s;
	var time = year+"-"+month+"-"+day+" "+hour+":"+min+":"+s;
	document.getElementById("span").innerHTML = time;
	return time;
}

//页面加载事件
window.onload = function(){
	showTime();
	window.setInterval(showTime,1000)
}
function sousuo(){
	//获取输入框的值
	var content = document.getElementById("content").value;
	alert("搜索内容："+content);
}
// 图片切换脚本代码
window.onload = function(){

	window.setInterval(showImg,3000)

		
		// 给数字li绑定事件
		var numsLis = document.getElementById("nums").getElementsByTagName("li");
		for(var i = 0; i < numsLis.length; i++){
			numsLis[i].onclick = function(){
				console.log(this.innerHTML)
				index = parseInt(this.innerHTML) - 1;// 显示的图片的索引值
				showImg();// 显示图片
			}
		}
}


var index = 0;
function showImg(){
	var imgsLis = document.getElementById("imgs").getElementsByTagName("li");
	var numsLis = document.getElementById("nums").getElementsByTagName("li");
	for(var i = 0; i < imgsLis.length; i++) {
		if(i == index){
			imgsLis[i].style.display = 'block';
			numsLis[i].style.backgroundColor = 'red';
		} else {
			imgsLis[i].style.display = 'none';
			numsLis[i].style.backgroundColor = '#808080';
		}
	}
	index ++;
	// 边界
	if(index == imgsLis.length){
		index = 0;
	}
}


$(function($){
	$.getJSON('http://127.0.0.1:8080/AdimgsServlet',{},function(data){
		console.log(data)
		
		if(data.length == 4){
			var content = ''
			for(var i=0; i<data.length; i ++){
				content = content + '<li><a href="' + data[i].img_page + '"><img src="http://127.0.0.1:8080/'+ data[i].img_url +'" alt="'+ data[i].img_desc +'"></a></li>'
			}
			
			document.getElementById('imgs').innerHTML =content;
			
		}
		
	});
});



$(function($){
	
	
});

// tab的显示效果
function showTab(id){
	if(id=='computer'){
		document.getElementById(id).style.display='block';
		document.getElementById('phone').style.display='none'
		document.getElementById('center_right_b_t').className='computer'
	}else{
		document.getElementById(id).style.display='block';
		document.getElementById('computer').style.display='none'
		document.getElementById('center_right_b_t').className='phone'
	}
}


// 广告隐藏
function hiddenAd(id){
	document.getElementById(id).style.display='none'
}